import Api from '../../utils/api.js';

const app = getApp();
// pages/mine/mine.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userType: '',
    todoCount: 0, // 待审批数量

    name: '',
    tel: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      name: app.globalData.userInfo.userName,
      tel: app.globalData.userInfo.userTel,
      userType: app.globalData.userInfo.userType
    }, () => {
      if (this.data.userType !== '3') {
        this.getMyApproves();
      }
    });
  },

  /* --======================数据接口======================-- */
  // 查询我的审批信息
  async getMyApproves () {
    const res = await Api.getMyApproves({ sessionKey: app.globalData.sessionKey });
    if (res) {
      app.globalData.myApproval = res.message;
      const todoCount = res.message.todo ? res.message.todo.length : 0;
      this.setData({ todoCount });
    }
  },

  /* --======================事件处理======================-- */
  // 我的审批点击处理
  handleMyApprovalTap () {
    wx.navigateTo({
      url: '/pages/myApproval/myApproval'
    });
  },
  // 我的月月点击处理
  handleMyOrderTap () {
    wx.navigateTo({
      url: '/pages/myOrder/myOrder'
    });
  }
});